<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <link href="css/login.css" rel="stylesheet" type="text/css"/>
    <title>后台管理</title>
</head>
<body>
<form action="login" method="post">
    <div class="login-wrapper">
        <div class="login-left">
            <div class="h1">start</div>
        </div>
        <div class="login-right">
            <div class="h3">管理员登录</div>
            <div class="form-group">
                <table>
                    <tr>
                        <td>
                            <input type="text" placeholder="username" name="username" id="uname" style="width: 186px;">
                        </td>
                        <td>
                            <div id="tip" style="width:120px;"></div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="form-group">
                <table>
                    <tr>
                        <td>
                            <input type="password" placeholder="password" name="password" style="width: 186px;"
                                   id="pwd">
                        </td>
                        <td>
                            <div id="tip2" style="width:120px;"></div>
                        </td>
                    </tr>
                </table>

            </div>
            <div class="button-area">
                <input type="submit" class="btn btn-submit" value="登录">
            </div>
        </div>
    </div>
</form>

<script>
    var openLoginRight = document.querySelector('.h1');
    var loginWrapper = document.querySelector('.login-wrapper');
    openLoginRight.addEventListener('click', function () {
        loginWrapper.classList.toggle('open');
    });

    $('#uname').blur(function () {
        var data = $('#uname').val();
        if (data == null || data == "") {
            $('#tip').text("用户名不能为空");
            $('#tip').css("color", "red");
        } else {
            $.ajax({
                    type: "get",
                    url: "checkName",
                    data: "username=" + data,
                    beforeSend: function () {
                        $('#tip').text("查询中...");
                    },
                    success: function (data) {
                        if (data == "yes") {
                            $('#tip').text("正确");
                            $('#tip').css("color", "blue");
                        } else if (data == "no") {
                            $('#tip').text("账号不存在");
                            $('#tip').css("color", "red");
                        }
                    }
                }
            );
        }
    });

    $('#pwd').blur(function () {
        var data = $('#pwd').val();
        if (data == null || data == "") {
            $('#tip2').text("密码不能为空");
            $('#tip2').css("color", "red");
        } else {
            $('#tip2').text(" ");
        }
    });
</script>
</body>
</html>